var avatar = false; //是否上传了头像
var titleCommons = "";  //职称
var nationalityCommons = ""; //国家
var academicDegreeCommons = ""; //学位
var outstandingCommons = ""; //杰出人才


$(document).ready(function () {
    var url = "/common/constant";
    requestGetAjax(url, function (resData) {
        if (resData.code === 200) {
          var gender = resData.gender;
            var nation = resData.nation;
            var politicCountenance = resData.politicCountenance;
            var country = resData.country;
            var title = resData.title;
            var academicDegree = resData.academicDegree;
            var outstanding = resData.outstanding;



            //性别
            if(null != gender){
                $("#gender").append(new Option("请选择","0"));
                if(gender != null && gender.length>0){
                    for(var i=0;i< gender.length;i++){
                        $("#gender").append(new Option(gender[i].name,gender[i].id));
                    }
                }
            }
            //民族
            if(null != nation){
                $("#ethnicity").append(new Option("请选择","0"));
                if(nation != null && nation.length>0){
                    for(var i=0;i< nation.length;i++){
                        $("#ethnicity").append(new Option(nation[i].name,nation[i].id));
                    }
                }
            }
            //政治面貌
            if(null != politicCountenance){
                $("#politicCountenance").append(new Option("请选择","0"));
                if(politicCountenance != null && politicCountenance.length>0){
                    for(var i=0;i< politicCountenance.length;i++){
                        $("#politicCountenance").append(new Option(politicCountenance[i].name,politicCountenance[i].id));
                    }
                }
            }
            //国家
            if(null != country){
                nationalityCommons = country;
                $("#nationality").append(new Option("请选择","0"));
                $("#degreeCountryId0").append(new Option("请选择","0"));
                $("#academicDegreeCountryId0").append(new Option("请选择","0"));
                $("#overSeaExperienceCountryId0").append(new Option("请选择","0"));
                $("#postdoctorCountryId0").append(new Option("请选择","0"));
                $("#academicianCountryId0").append(new Option("请选择","0"));
                if(country != null && country.length>0){
                    for(var i=0;i< country.length;i++){
                        $("#nationality").append(new Option(country[i].name,country[i].id));
                        $("#degreeCountryId0").append(new Option(country[i].name,country[i].id));
                        $("#academicDegreeCountryId0").append(new Option(country[i].name,country[i].id));
                        $("#overSeaExperienceCountryId0").append(new Option(country[i].name,country[i].id));
                        $("#postdoctorCountryId0").append(new Option(country[i].name,country[i].id));
                        $("#academicianCountryId0").append(new Option(country[i].name,country[i].id));

                    }
                    $("#nationality").comboSelect();
                    $("#nationality").css('display', 'none');
                    $("#degreeCountryId0").comboSelect();
                    $("#degreeCountryId0").css('display', 'none');
                    $("#academicDegreeCountryId0").comboSelect();
                    $("#academicDegreeCountryId0").css('display', 'none');
                    $("#overSeaExperienceCountryId0").comboSelect();
                    $("#overSeaExperienceCountryId0").css('display', 'none');
                    $("#postdoctorCountryId0").comboSelect();
                    $("#postdoctorCountryId0").css('display', 'none');
                    $("#academicianCountryId0").comboSelect();
                    $("#academicianCountryId0").css('display', 'none');
                }
            }
            //职称
            if(null != title){
                titleCommons = title;
                $("#positionTitle0").append(new Option("请选择","0"));
                $("#overSeaExperienceTitleId0").append(new Option("请选择","0"));
                if(title != null && title.length>0){
                    for(var i=0;i< title.length;i++){
                        $("#positionTitle0").append(new Option(title[i].name,title[i].id));
                        $("#overSeaExperienceTitleId0").append(new Option(title[i].name,title[i].id));
                    }
                }
            }

            //学位
            if(null != academicDegree){
                academicDegreeCommons = academicDegree;
                $("#educationAcademicDegreeId0").append(new Option("请选择","0"));
                $("#degreeDegreeNameId0").append(new Option("请选择","0"));
                if(academicDegree != null && academicDegree.length>0){
                    for(var i=0;i< academicDegree.length;i++){
                        $("#educationAcademicDegreeId0").append(new Option(academicDegree[i].name,academicDegree[i].id));
                        $("#degreeDegreeNameId0").append(new Option(academicDegree[i].name,academicDegree[i].id));
                    }
                }
            }

            //杰出人才

            if(null != outstanding){
                outstandingCommons = outstanding;
                $("#outstandingTitleId0").append(new Option("请选择","0"));
                if(outstanding != null && outstanding.length>0){
                    for(var i=0;i< outstanding.length;i++){
                        $("#outstandingTitleId0").append(new Option(outstanding[i].name,outstanding[i].id));
                    }
                }
            }

        } else {
            alert(resData.errMsg);
        }
    });

    $('body input').val();
    var pro=["北京市", "天津市", "河北省", "山西省", "内蒙古自治区", "辽宁省", "吉林省", "黑龙江省", "上海市", "江苏省", "浙江省", "安徽省", "福建省", "江西省", "山东省", "河南省", "湖北省", "湖南省", "广东省", "广西壮族自治区", "海南省", "重庆市", "四川省", "贵州省", "云南省", "西藏自治区", "陕西省", "甘肃省", "青海省", "宁夏回族自治区", "新疆维吾尔自治区", "台湾省", "香港特别行政区", "澳门特别行政区"];
    var city = new Array(pro.length);
    city[0] = ["北京市"];
    city[1] = ["天津市"];
    city[2] = ["石家庄市","唐山市","秦皇岛市","邯郸市","邢台市","保定市","张家口市","承德市","沧州市","廊坊市","衡水市"];
    city[3] = ["太原市","大同市","阳泉市","长治市","晋城市","朔州市","晋中市","运城市","忻州市","临汾市","吕梁市"];
    city[4] = ["呼和浩特市","包头市","乌海市","赤峰市","通辽市","鄂尔多斯市","呼伦贝尔市","巴彦淖尔市","乌兰察布市","兴安盟","锡林郭勒盟","阿拉善盟"];
    city[5] = ["沈阳市","大连市","鞍山市","抚顺市","本溪市","丹东市","锦州市","营口市","阜新市","辽阳市","盘锦市","铁岭市","朝阳市","葫芦岛市"];
    city[6] = ["长春市","吉林市","四平市","辽源市","通化市","白山市","松原市","白城市","延边朝鲜族自治州"];
    city[7] = ["哈尔滨市","齐齐哈尔市","鸡西市","鹤岗市","双鸭山市","大庆市","伊春市","佳木斯市","七台河市","牡丹江市","黑河市","绥化市","大兴安岭地区"];
    city[8] = ["上海市"];
    city[9] = ["南京市","无锡市","徐州市","常州市","苏州市","南通市","连云港市","淮安市","盐城市","扬州市","镇江市","泰州市","宿迁市"];
    city[10] = ["杭州市","宁波市","温州市","嘉兴市","湖州市","绍兴市","金华市","衢州市","舟山市","台州市","丽水市"];
    city[11] = ["合肥市","芜湖市","蚌埠市","淮南市","马鞍山市","淮北市","铜陵市","安庆市","黄山市","滁州市","阜阳市","宿州市","六安市","亳州市","池州市","宣城市"];
    city[12] = ["福州市","厦门市","莆田市","三明市","泉州市","漳州市","南平市","龙岩市","宁德市"];
    city[13] = ["南昌市","景德镇市","萍乡市","九江市","新余市","鹰潭市","赣州市","吉安市","宜春市","抚州市","上饶市"];
    city[14] = ["济南市","青岛市","淄博市","枣庄市","东营市","烟台市","潍坊市","济宁市","泰安市","威海市","日照市","莱芜市","临沂市","德州市","聊城市","滨州市","菏泽市"];
    city[15] = ["郑州市","开封市","洛阳市","平顶山市","安阳市","鹤壁市","新乡市","焦作市","濮阳市","许昌市","漯河市","三门峡市","南阳市","商丘市","信阳市","周口市","驻马店市","济源市"];
    city[16] = ["武汉市","黄石市","十堰市","宜昌市","襄阳市","鄂州市","荆门市","孝感市","荆州市","黄冈市","咸宁市","随州市","恩施土家族苗族自治州","仙桃市","潜江市","天门市","神农架林区"];
    city[17] = ["长沙市","株洲市","湘潭市","衡阳市","邵阳市","岳阳市","常德市","张家界市","益阳市","郴州市","永州市","怀化市","娄底市","湘西土家族苗族自治州"];
    city[18] = ["广州市","韶关市","深圳市","珠海市","汕头市","佛山市","江门市","湛江市","茂名市","肇庆市","惠州市","梅州市","汕尾市","河源市","阳江市","清远市","东莞市","中山市","潮州市","揭阳市","云浮市"];
    city[19] = ["南宁市","柳州市","桂林市","梧州市","北海市","防城港市","钦州市","贵港市","玉林市","百色市","贺州市","河池市","来宾市","崇左市"];
    city[20] = ["海口市","三亚市","三沙市","儋州市","五指山市","琼海市","文昌市","万宁市","东方市","定安县","屯昌县","澄迈县","临高县","白沙黎族自治县","昌江黎族自治县","乐东黎族自治县","陵水黎族自治县","保亭黎族苗族自治县","琼中黎族苗族自治县"];
    city[21] = ["重庆市"];
    city[22] = ["成都市","自贡市","攀枝花市","泸州市","德阳市","绵阳市","广元市","遂宁市","内江市","乐山市","南充市","眉山市","宜宾市","广安市","达州市","雅安市","巴中市","资阳市","阿坝藏族羌族自治州","甘孜藏族自治州","凉山彝族自治州"];
    city[23] = ["贵阳市","六盘水市","遵义市","安顺市","毕节市","铜仁市","黔西南布依族苗族自治州","黔东南苗族侗族自治州","黔南布依族苗族自治州"];
    city[24] = ["昆明市","曲靖市","玉溪市","保山市","昭通市","丽江市","普洱市","临沧市","楚雄彝族自治州","红河哈尼族彝族自治州","文山壮族苗族自治州","西双版纳傣族自治州","大理白族自治州","德宏傣族景颇族自治州","怒江傈僳族自治州","迪庆藏族自治州"];
    city[25] = ["拉萨市","日喀则市","昌都市","林芝市","山南市","那曲市","阿里地区"];
    city[26] = ["西安市","铜川市","宝鸡市","咸阳市","渭南市","延安市","汉中市","榆林市","安康市","商洛市"];
    city[27] = ["兰州市","嘉峪关市","金昌市","白银市","天水市","武威市","张掖市","平凉市","酒泉市","庆阳市","定西市","陇南市","临夏回族自治州","甘南藏族自治州"];
    city[28] = ["西宁市","海东市","海北藏族自治州","黄南藏族自治州","海南藏族自治州","果洛藏族自治州","玉树藏族自治州","海西蒙古族藏族自治州"];
    city[29] = ["银川市","石嘴山市","吴忠市","固原市","中卫市"];
    city[30] = ["乌鲁木齐市","克拉玛依市","吐鲁番市","哈密市","昌吉回族自治州","博尔塔拉蒙古自治州","巴音郭楞蒙古自治州","阿克苏地区","克孜勒苏柯尔克孜自治州","喀什地区","和田地区","伊犁哈萨克自治州","塔城地区","阿勒泰地区","石河子市","阿拉尔市","图木舒克市","五家渠市","北屯市","铁门关市","双河市","可克达拉市","昆玉市"];
    city[31] = ["台湾省"];
    city[32] = ["香港特别行政区"];
    city[33] = ["澳门特别行政区"];

    for(var i=0;i<pro.length;i++){
        $("#province").append($("<option></option>").val(i+1 +',' + pro[i]).html(pro[i]));
    }
    $("#province").change(function(){
        arr = $(this).val().split(",");
        var index=arr[0]-1;//获取当前省的下标
        $("#city").prop("length",1);//清空原有的数据
        for(var i=0;i<city[index].length;i++){//重新为市赋值
            $("#city").append($("<option>").val(city[index][i]).html(city[index][i]));
        }
    });
});

$(window).load(function () {

    //出生年月
/*    laydate.render({
        elem: '#birthday' //指定元素
    });*/
    //加入组织时间
    laydate.render({
        elem: '#politicalstatustime' //指定元素
    });
    //主要工作经历任职开始年月
    laydate.render({
        elem: '#positionStartdate0', //指定元素
        type: 'month'
    });
    laydate.render({
        elem: '#positionEnddate0', //指定元素
        type: 'month'
    });
    //现任职务
    laydate.render({
        elem: '#positionStartdateXrzw0', //指定元素
        // showBottom: false
        type: 'month'
    });
    laydate.render({
        elem: '#positionEnddateXrzw0', //指定元素
        // showBottom: false
        type: 'month'
    });
    //现任职称
    laydate.render({
        elem: '#positionStartdateXrzc0', //指定元素
        // showBottom: false
        type: 'month'
    });
    laydate.render({
        elem: '#positionEnddateXrzc0', //指定元素
        // showBottom: false
        type: 'month'

    });
    //社会任职
    laydate.render({
        elem: '#positionStartdateShrz0', //指定元素
        // showBottom: false
        type: 'month'
    });
    laydate.render({
        elem: '#positionEnddateShrz0', //指定元素
        type: 'month'
    });
    //学术任职
    laydate.render({
        elem: '#positionStartdateXsrz0', //指定元素
        // showBottom: false
        type: 'month'
    });
    laydate.render({
        elem: '#positionEnddateXsrz0', //指定元素
        // showBottom: false
        type: 'month'
    });

    //评审专家
    laydate.render({
        elem: '#reviewDate0', //指定元素
        // showBottom: false
    });

    //最高学位
    laydate.render({
        elem: '#startdate0', //指定元素
    });
    laydate.render({
        elem: '#enddate0', //指定元素
    });

    //学历
    laydate.render({
        elem: '#startdateEdu0', //指定元素
    });

    laydate.render({
        elem: '#enddateEdu0', //指定元素
    });


    //海外交流/学习/研究经历
    laydate.render({
        elem: '#startdateYjjl0', //指定元素
    });

    laydate.render({
        elem: '#enddateYjjl0', //指定元素
    });


    //博士后经历
    laydate.render({
        elem: '#startdateDoctor0', //指定元素
    });

    laydate.render({
        elem: '#enddateDoctor0', //指定元素
    });

    //获奖情况
    laydate.render({
        elem: '#awardDate0', //指定元素
    });
    //荣誉
    laydate.render({
        elem: '#honorDate0', //指定元素
    });
    //院士
    laydate.render({
        elem: '#academicianDate0', //指定元素
    });
    //杰出人才
    laydate.render({
        elem: '#outstandingDate0', //指定元素
    });

    //首位/领军人物
    laydate.render({
        elem: '#leaderDate0', //指定元素
    });



    //主要工作经历“至今”
    $('#positionEnddateClick0').click(function () {
        const isChecked = $('#positionEnddateClick0').is(":checked");
        if (isChecked) {
            $('#positionEnddate0').attr('disabled', true);
        } else {
            $('#positionEnddate0').prop('disabled', false);
        }
    });

    //现任职务-“至今”
    $('#positionEnddateClickXrzw0').click(function () {
        const isChecked = $('#positionEnddateClickXrzw0').is(":checked");
        if (isChecked) {
            $('#positionEnddateXrzw0').attr('disabled', true);
        } else {
            $('#positionEnddateXrzw0').prop('disabled', false);
        }
    });

    //现任职称-“至今”
    $('#positionEnddateClickXrzc0').click(function () {
        const isChecked = $('#positionEnddateClickXrzc0').is(":checked");
        if (isChecked) {
            $('#positionEnddateXrzc0').attr('disabled', true);
        } else {
            $('#positionEnddateXrzc0').prop('disabled', false);
        }
    });
    //社会职称-“至今”
    $('#positionEnddateClickShrz0').click(function () {
        const isChecked = $('#positionEnddateClickShrz0').is(":checked");
        if (isChecked) {
            $('#positionEnddateShrz0').attr('disabled', true);
        } else {
            $('#positionEnddateShrz0').prop('disabled', false);
        }
    });
    //学术任职-“至今”
    $('#positionEnddateClickXsrz0').click(function () {
        const isChecked = $('#positionEnddateClickXsrz0').is(":checked");
        if (isChecked) {
            $('#positionEnddateXsrz0').attr('disabled', true);
        } else {
            $('#positionEnddateXsrz0').prop('disabled', false);
        }
    });
    //最高学位-“至今”
    $('#enddateClick0').click(function () {
        const isChecked = $('#enddateClick0').is(":checked");
        if (isChecked) {
            $('#enddate0').attr('disabled', true);
        } else {
            $('#enddate0').prop('disabled', false);
        }
    });

    //学历-“至今”
    $('#enddateEdu0Click0').click(function () {
        const isChecked = $('#enddateEdu0Click0').is(":checked");
        if (isChecked) {
            $('#enddateEdu0').attr('disabled', true);
        } else {
            $('#enddateEdu0').prop('disabled', false);
        }
    });

    //海外交流/学习/研究经历-“至今”
    $('#enddateClickYjjl0').click(function () {
        const isChecked = $('#enddateClickYjjl0').is(":checked");
        if (isChecked) {
            $('#enddateYjjl0').attr('disabled', true);
        } else {
            $('#enddateYjjl0').prop('disabled', false);
        }
    });

    //海外交流/学习/研究经历-“至今”
    $('#enddateDoctorClick0').click(function () {
        const isChecked = $('#enddateDoctorClick0').is(":checked");
        if (isChecked) {
            $('#enddateDoctor0').attr('disabled', true);
        } else {
            $('#enddateDoctor0').prop('disabled', false);
        }
    });




    //添加tr
    $(function () {
        //$("#addrow1").click(addrow);//绑定添加事件
        $("#addrow1").click(function () {
            addrow("table1");
        });
        $("#removerow1").click(function () {
            removerow("table1");
        });//绑定删除事件。
        $("#addrow2").click(function () {
            addrow("table2");
        });//绑定添加事件
        $("#removerow2").click(function () {
            removerow("table2");
        });//绑定删除事件。
        $("#addrow").click(function () {
            addrow("table3");
        });//绑定添加事件
        $("#removerow").click(function () {
            removerow("table3");
        });//绑定删除事件。
    });
});

function updateSAttributes(updateHtml, findType, attrName, oldContent, newContent) {
    var idContentSelect = $(updateHtml).find(findType).attr(attrName);
    if (idContentSelect) {
        idContentSelect = idContentSelect.replace(new RegExp(oldContent, "gm"), newContent);
        $(updateHtml).find(findType).attr(attrName, idContentSelect);
    }
    return updateHtml;
}

function addtr(tableId, copyTableId) {
    var table = $("#" + tableId);
    var tableTrNum = (table.find('tr').length - 1);
    var copyTable = $("#" + copyTableId).clone();
    var copyTr = copyTable.find('tr');
    var copyTdAll = copyTable.find('td');
    for (var i = 1; i < copyTdAll.length; i++) {
        copyTdAll[i] = updateSAttributes(copyTdAll[i], 'div select', 'id', '1Copy', (tableTrNum));
        copyTdAll[i] = updateSAttributes(copyTdAll[i], 'div select', 'name', '1Copy', (tableTrNum));
        copyTdAll[i] = updateSAttributes(copyTdAll[i], 'div select', 'onchange', '1Copy', (tableTrNum));
        copyTdAll[i] = updateSAttributes(copyTdAll[i], 'div select', 'onclick', '1Copy', (tableTrNum));
        copyTdAll[i] = updateSAttributes(copyTdAll[i], 'div input', 'id', '1Copy', (tableTrNum));
        copyTdAll[i] = updateSAttributes(copyTdAll[i], 'div input', 'name', '1Copy', (tableTrNum));
        copyTdAll[i] = updateSAttributes(copyTdAll[i], 'div input', 'onchange', '1Copy', (tableTrNum));
        copyTdAll[i] = updateSAttributes(copyTdAll[i], 'div input', 'onclick', '1Copy', (tableTrNum));


    }
    var copyTdSpan = $(copyTdAll[0]).find("div p");
    $(copyTdSpan).text(tableTrNum + 1);
    table.append(copyTr);
    //主要工作经历任职开始年月
    laydate.render({
        elem: '#positionStartdate'  + tableTrNum //指定元素
        , type: 'month'
    });
    laydate.render({
        elem: '#positionEnddate' + tableTrNum //指定元素
        , type: 'month'
    });
    //现任职务
    laydate.render({
        elem: '#positionStartdateXrzw' + tableTrNum, //指定元素
        type: 'month'
        // showBottom: false
    });
    laydate.render({
        elem: '#positionEnddateXrzw' + tableTrNum, //指定元素
        type: 'month'
        // showBottom: false
    });
    //现任职称
    laydate.render({
        elem: '#positionStartdateXrzc' + tableTrNum, //指定元素
        type: 'month',
        // showBottom: false
    });
    laydate.render({
        elem: '#positionEnddateXrzc' + tableTrNum, //指定元素
        type: 'month',
        // showBottom: false
    });
    //社会任职
    laydate.render({
        elem: '#positionStartdateShrz' + tableTrNum, //指定元素
        // showBottom: false
         type: 'month'
    });
    laydate.render({
        elem: '#positionEnddateShrz' + tableTrNum, //指定元素
        type: 'month'
    });
    //学术任职
    laydate.render({
        elem: '#positionStartdateXsrz' + tableTrNum, //指定元素
        // showBottom: false
        type: 'month'
    });
    laydate.render({
        elem: '#positionEnddateXsrz' + tableTrNum, //指定元素
        // showBottom: false
        type: 'month'
    });

    //评审专家
    laydate.render({
        elem: '#reviewDate' + tableTrNum, //指定元素
        // showBottom: false
    });

    //最高学位
    laydate.render({
        elem: '#startdate' + tableTrNum, //指定元素
    });
    laydate.render({
        elem: '#enddate' + tableTrNum, //指定元素
    });

    //学历
    laydate.render({
        elem: '#startdateEdu'+ tableTrNum, //指定元素
    });

    laydate.render({
        elem: '#enddateEdu'+ tableTrNum, //指定元素
    });


    //海外交流/学习/研究经历
    laydate.render({
        elem: '#startdateYjjl'+ tableTrNum, //指定元素
    });

    laydate.render({
        elem: '#enddateYjjl'+ tableTrNum, //指定元素
    });


    //博士后经历
    laydate.render({
        elem: '#startdateDoctor'+ tableTrNum, //指定元素
    });

    laydate.render({
        elem: '#enddateDoctor'+ tableTrNum, //指定元素
    });

    //获奖情况
    laydate.render({
        elem: '#awardDate'+ tableTrNum, //指定元素
    });

    //荣誉
    laydate.render({
        elem: '#honorDate'+ tableTrNum, //指定元素
    });

    //院士
    laydate.render({
        elem: '#academicianDate'+ tableTrNum, //指定元素
    });

    //杰出人才
    laydate.render({
        elem: '#outstandingDate'+ tableTrNum, //指定元素
    });

    //首位/领军人物
    laydate.render({
        elem: '#leaderDate'+ tableTrNum, //指定元素
    });

    if("table3" == tableId){
        //加载职称
        $("#positionTitle" + tableTrNum).append(new Option("请选择","0"));
        if(titleCommons != null && titleCommons.length>0){
            for(var i=0;i< titleCommons.length;i++){
                $("#positionTitle" + tableTrNum).append(new Option(titleCommons[i].name,titleCommons[i].id));
            }
        }
    }else  if("table7" == tableId){
        //最高学位国家
        $("#degreeCountryId" + tableTrNum).append(new Option("请选择","0"));
        if(nationalityCommons != null && nationalityCommons.length>0){
            for(var i=0;i< nationalityCommons.length;i++){
                $("#degreeCountryId" + tableTrNum).append(new Option(nationalityCommons[i].name,nationalityCommons[i].id));
            }
            $("#degreeCountryId" + tableTrNum).comboSelect();
            $("#degreeCountryId" + tableTrNum).css('display', 'none');
        }
        //加载学位
        $("#degreeDegreeNameId" + tableTrNum).append(new Option("请选择","0"));
        if(academicDegreeCommons != null && academicDegreeCommons.length>0){
            for(var i=0;i< academicDegreeCommons.length;i++){
                $("#degreeDegreeNameId" + tableTrNum).append(new Option(academicDegreeCommons[i].name,academicDegreeCommons[i].id));
            }
        }

    }else if("table9" == tableId){
        //学历学位授予国家
        $("#academicDegreeCountryId" + tableTrNum).append(new Option("请选择","0"));
        if(nationalityCommons != null && nationalityCommons.length>0){
            for(var i=0;i< nationalityCommons.length;i++){
                $("#academicDegreeCountryId" + tableTrNum).append(new Option(nationalityCommons[i].name,nationalityCommons[i].id));
            }
            $("#academicDegreeCountryId" + tableTrNum).comboSelect();
            $("#academicDegreeCountryId" + tableTrNum).css('display', 'none');
        }
        //加载学位
        $("#educationAcademicDegreeId" + tableTrNum).append(new Option("请选择","0"));
        if(academicDegreeCommons != null && academicDegreeCommons.length>0){
            for(var i=0;i< academicDegreeCommons.length;i++){
                $("#educationAcademicDegreeId" + tableTrNum).append(new Option(academicDegreeCommons[i].name,academicDegreeCommons[i].id));
            }
        }
    }else  if("table10" == tableId){
        // 海外交流/学习/研究经历国家
        $("#overSeaExperienceCountryId" + tableTrNum).append(new Option("请选择","0"));
        if(nationalityCommons != null && nationalityCommons.length>0){
            for(var i=0;i< nationalityCommons.length;i++){
                $("#overSeaExperienceCountryId" + tableTrNum).append(new Option(nationalityCommons[i].name,nationalityCommons[i].id));
            }
            $("#overSeaExperienceCountryId" + tableTrNum).comboSelect();
            $("#overSeaExperienceCountryId" + tableTrNum).css('display', 'none');
        }
        //加载职称
        $("#overSeaExperienceTitleId" + tableTrNum).append(new Option("请选择","0"));
        if(titleCommons != null && titleCommons.length>0){
            for(var i=0;i< titleCommons.length;i++){
                $("#overSeaExperienceTitleId" + tableTrNum).append(new Option(titleCommons[i].name,titleCommons[i].id));
            }
        }

    }else if("table11" == tableId){
        // 博士后经历国家
        $("#postdoctorCountryId" + tableTrNum).append(new Option("请选择","0"));
        if(nationalityCommons != null && nationalityCommons.length>0){
            for(var i=0;i< nationalityCommons.length;i++){
                $("#postdoctorCountryId" + tableTrNum).append(new Option(nationalityCommons[i].name,nationalityCommons[i].id));
            }
            $("#postdoctorCountryId" + tableTrNum).comboSelect();
            $("#postdoctorCountryId" + tableTrNum).css('display', 'none');
        }
    }else if("table14" == tableId){
        // 院士国家
        $("#academicianCountryId" + tableTrNum).append(new Option("请选择","0"));
        if(nationalityCommons != null && nationalityCommons.length>0){
            for(var i=0;i< nationalityCommons.length;i++){
                $("#academicianCountryId" + tableTrNum).append(new Option(nationalityCommons[i].name,nationalityCommons[i].id));
            }
            $("#academicianCountryId" + tableTrNum).comboSelect();
            $("#academicianCountryId" + tableTrNum).css('display', 'none');
        }
    }else if("table15" == tableId){
        // 杰出人才
        $("#outstandingTitleId" + tableTrNum).append(new Option("请选择","0"));
        if(outstandingCommons != null && outstandingCommons.length>0){
            for(var i=0;i< outstandingCommons.length;i++){
                $("#outstandingTitleId" + tableTrNum).append(new Option(outstandingCommons[i].name,outstandingCommons[i].id));
            }
        }
    }



}

function confirmDelete(tableId, tdobject) {
    layer.confirm('您是否确定删除改行？', {
        btn: ['确定', '取消'] //按钮
    }, function () {
        var table = $("#" + tableId);
        var tableTrNum = (table.find('tr').length - 1);
        var td = $(tdobject);
        var tr = td.parents('tr:first');
        var serialNum = tr.find('td:first').find('div p').text();
        var tableTrAll = table.find('tr');
        while (tableTrAll.length > serialNum) {
            var currentTrAllTd = tableTrAll[serialNum];
            var currentTdAll = $(currentTrAllTd).find("td");
            for (var i = 1; i < currentTdAll.length; i++) {
                currentTdAll[i] = updateSAttributes(currentTdAll[i], 'div select', 'id', (serialNum - 1), (serialNum - 2));
                currentTdAll[i] = updateSAttributes(currentTdAll[i], 'div select', 'name', (serialNum - 1), (serialNum - 2));
                currentTdAll[i] = updateSAttributes(currentTdAll[i], 'div select', 'onchange', (serialNum - 1), (serialNum - 2));
                currentTdAll[i] = updateSAttributes(currentTdAll[i], 'div select', 'onclick', (serialNum - 1), (serialNum - 2));
                currentTdAll[i] = updateSAttributes(currentTdAll[i], 'div input', 'id', (serialNum - 1), (serialNum - 2));
                currentTdAll[i] = updateSAttributes(currentTdAll[i], 'div input', 'name', (serialNum - 1), (serialNum - 2));
                currentTdAll[i] = updateSAttributes(currentTdAll[i], 'div input', 'onchange', (serialNum - 1), (serialNum - 2));
                currentTdAll[i] = updateSAttributes(currentTdAll[i], 'div input', 'onclick', (serialNum - 1), (serialNum - 2));
            }
            $(currentTdAll[0]).find('div p').text(serialNum - 1);
            serialNum++;
        }
        tr.remove();
        layer.msg('删除成功', {icon: 1});

    });
}


// 验证中文名称
function isChinaName(name) {
    var pattern = /^[\u4E00-\u9FA5]{1,6}$/;
    return pattern.test(name);
}

// 验证手机号
function isPhoneNo(phone) {
    var pattern = /^1[34578]\d{9}$/;
    return pattern.test(phone);
}

// 验证身份证
function isCardNo(card) {
    var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    return pattern.test(card);
}

// 验证函数
function formValidate() {
    var str = '';
        // 判断名称
        if ($.trim($('#chinesename').val()).length == 0) {
            str += '请输入名称\n';
            $('#chinesename').focus();
        }else{
            if (isChinaName($.trim($('#chinesename').val())) == false) {
                str += '请输入汉字名称\n';
                $('#chinesename').focus();
            }
        }


    //性别
    if ( $('#gender').val()  == '0') {
        str += '请选择正确的性别\n';
        $('#gender').focus();
    }

    // 判断生日
    var birthdayPattern = /^\d{8}$/;
    if ($.trim($('#birthday').val()).length == 0) {
        str += '请输入生日年月日\n';
        $('#birthday').focus();
    }else{
        if (birthdayPattern.test($.trim($('#birthday').val())) == false) {
            str += '请输入正确的年月日\n';
            $('#birthday').focus();
        }
    }

    //民族
    if ( $('#ethnicity').val()  == '0') {
        str += '请选择正确的民族\n';
        $('#ethnicity').focus();
    }

    //国籍
    if ( $('#nationality').val()  == '0') {
        str += '请选择正确的国籍\n';
        $('#nationality').focus();
    }


    //政治面貌
    if ( $('#politicCountenance').val()  == '0') {
        str += '请选择正确的性别\n';
        $('#politicCountenance').focus();
    }


    //省
    if ( $('#province').val()  == '0') {
        str += '请选择正确的省份\n';
        $('#province').focus();
    }


    //市
    if ( $('#city').val()  == '0') {
        str += '请选择正确的市区\n';
        $('#city').focus();
    }

return str;




}



// 头像预览
$("#avatar").change(function () {
    var choose_file = $(this)[0].files[0];
    var ftype=choose_file.name.substring(choose_file.name.lastIndexOf(".")+1);
    if(ftype=="jpg" || ftype=="png" || ftype=="jpeg" || ftype == "JPG"){
        var size = choose_file.size / 1024 / 1024;
        if (size > 1) {
            alert("头像不能大于1M");
            return false;
        }
    // 实例化一个阅读器对象
    var reader = new FileReader();
    // 读取文件的路径，没有返回值,结果在reader.result里
    reader.readAsDataURL(choose_file);
    // 读取需要时间，读完后再修改图片路径
    reader.onload=function () {
        $("#avatar_img").attr("src",this.result);
        avatar = true;
    }
    }else{
        alert("头像格式不对，请重新选择！");
        return false;
    }
});

function personSaveSubmit() {
    if (avatar) {
        var validForm = $('#personForm').validate();
        var flag = validForm.form();
        if (flag) {
            var str = formValidate();
            if (str != '') {
                alert(str);
                return false;
            }
            $("#personForm").ajaxSubmit({
                type: 'post',
                url: '/person/personSave',
                dataType: 'json',
                success: function (data) {
                    console.log(JSON.stringify(data));
                    if (data.code === 200) {
                        alert(data.errMsg);
                        window.location.reload();
                    } else if (data.code === 500) {
                        alert(data.errMsg);
                    }
                }
            });
        } else {
            alert("请填写必填项后再提交！");
            return false;
        }
    } else {
        alert("请上传正确格式头像后再提交！");
        $('#avatar').focus();
        return false;
    }
}



$('input[name="orgName"]').keyup(function () {
    showUnitSuggestForUnitPathAfterT();
});

var flag;  //全局变量用于标识是否延时执行keyup事件
function showUnitSuggestForUnitPathAfterT() {
    clearTimeout(flag);
    flag = setTimeout(function () {
        showUnitSuggestForPPDiv();
    }, 500);
}


function showUnitSuggestForPPDiv() {
    var url = "/organ/organInfoByName";
    var input = $.trim($("#orgName").val());

    if (input === '') {
        $("#unitDRecommend").html("");
        $("#unitDRecommend").hide();
    } else {
        requestPostAjax(url, true, {"organName": input}, function (resData) {
            var unitSuggest = $("#unitDRecommend");
            unitSuggest.show().html("");
            if (resData.length === 0) {
                unitSuggest.text("没有相关数据!");
            } else {
                var contentR = '';
                for (var i = 0; i < resData.length; i++) {
                    if (i < resData.length - 1)
                        contentR += '&nbsp;&nbsp;<a onclick="submitSelectPCode(this)" rel="' + resData[i].orgName + '|' + resData[i].orgId + '">' + resData[i].orgName + '</a><br>';
                    else
                        contentR += '&nbsp;&nbsp;<a onclick="submitSelectPCode(this)" rel="' + resData[i].orgName + '|' + resData[i].orgId + '">' + resData[i].orgName + '</a>';
                }
                unitSuggest.append(contentR);
            }
        });

    }
}



function submitSelectPCode(obj) {
    var paramIn = obj.rel;
    $("#orgName").val(paramIn.split('|')[0]);
    $("#orgName").attr('data-toggle', paramIn.split('|')[1]);
    $("#unitDRecommend").html("");
    $("#unitDRecommend").hide();
}

